package com.woniuxy.house.provider;

import com.woniuxy.house.entity.User;
import org.apache.ibatis.jdbc.SQL;

/**
 * @author baobo
 * @date 2022-08-27-16:31
 */
public class UserSqlProvider {
	/**
	 * 用户可修改字段
	 * @param user
	 * @return
	 */
	public String update(User user) {
		return  new SQL() {
			{
				UPDATE("house_user");
				if(user.getAccount()!=null){
					SET("account=#{account}");
				}
				if(user.getOtherAccount()!=null){
					SET("other_account=#{otherAccount}");
				}
				if(user.getPassword()!=null){
					SET("password=#{password}");
				}
				if(user.getHeadPhoto()!=null){
					SET("head_photo=#{headPhoto}");
				}
				if(user.getTelephone()!=null){
					SET("telephone=#{telephone}");
				}
				if(user.getRegistTime()!=null){
					SET("regist_time=#{registTime}");
				}
				if(user.getUserSign()!=null){
					SET("user_sign=#{userSign}");
				}
				if(user.getStatus()!=null){
					SET("status=#{status}");
				}
				WHERE("id=#{id}");
			}
		}.toString();
	}
	public String getUserListByCondition(User user) {
		return  new SQL() {
			{
				SELECT("*");
				FROM("house_user");
				if(user.getAccount()!=null){
					WHERE("account=#{account}");
				}
				if(user.getOtherAccount()!=null){
					WHERE("other_account=#{otherAccount}");
				}
				if(user.getPassword()!=null){
					WHERE("password=#{password}");
				}
				if(user.getHeadPhoto()!=null){
					WHERE("head_photo=#{headPhoto}");
				}
				if(user.getTelephone()!=null){
					WHERE("telephone=#{telephone}");
				}
				if(user.getRegistTime()!=null){
					WHERE("regist_time=#{registTime}");
				}
				if(user.getUserSign()!=null){
					WHERE("user_sign=#{userSign}");
				}
				if(user.getStatus()!=null){
					WHERE("status=#{status}");
				}
				if(user.getId()!=null){
					WHERE("id=#{id}");
				}
			}
		}.toString();
	}
}